const registerRouter = require('./backend/router')
const path = require('path')
const webpack = require('webpack')
const CompressionPlugin = require('compression-webpack-plugin')
function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = {
  css: {
    loaderOptions: {
      sass: {
        // 全局引入变量和 mixin
        prependData: `
          @import "@/assets/scss/variable.scss";
          @import "@/assets/scss/mixin.scss";
        `
      }
    }
  },
  devServer: {
    before(app) {
      registerRouter(app)
    },
    open: true
  },
  configureWebpack: {
    name: 'vue-music',
    resolve: {
      alias: {
        components: resolve('src/components'),
        directives: resolve('src/directives'),
        backend: resolve('src/backend'),
        mixins: resolve('src/mixins'),
        service: resolve('src/service'),
        assets: resolve('src/assets'),
        views: resolve('src/views'),
        utils: resolve('src/utils'),
        api: resolve('src/api'),
        '@': resolve('src')
      }
    },
    // webpack plugins
    plugins: [
      // Ignore all locale files of moment.js
      new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
      // gzip files
      new CompressionPlugin({
        test: /\.js$|\.css$|\.html$/,
        threshold: 1024 * 10,
        deleteOriginalAssets: false
      })
    ]
  }
}
